var roles = requestData(path+"/role");
var departments = requestData(path+"/department");

$(function(){
	
   var data = {
		method: 'GET',
		url:path+'/human-resource/staff-files',
		columns:[{
			checkbox: true
		}, {
			field: 'empId',
			title: '编号',
			visible: false
		}, {
			field: 'empName',
			title: '姓名',
			searchable: true
		}, {
			field: 'empAge',
			title: '年龄',
			sortable: true
		}, {
			field: 'empSex',
			title: '性别',
			searchable: true
		}, {
			field: 'empDomicilePlace',
			title: '户籍地'
		}, {
			field: 'empNativePlace',
			title: '籍贯',
			searchable: true
		}, {
			field: 'empMarriage',
			title: '婚姻',
			searchable: true
		}, {
			field: 'empBirthDay',
			title: '出生年月'
		}, {
			field: 'empCard',
			title: '身份证'
		},{
			field: 'empWorkState',
			title: '就职状态',
		    formatter: function(value, row, index) {
				switch(value){
				  case "在职":
					return '<span class="layui-badge layui-bg-green">在职</span>';
				  case "请假":
					return '<span class="layui-badge layui-bg-orange">请假</span>';
				  case "离职":
					return '<span class="layui-badge">离职</span>';
				}
			   return '<span class="layui-badge">未设置就职状态</span>';
			}
		}, {
			field: 'empEducation',
			title: '学历',
			searchable: true
		}, {
			field: 'empPhone',
			title: '联系电话'
		}, {
			field: 'empEntryDate',
			title: '入职时间',
			sortable: true
		}, {
			field: 'empQuitDate',
			title: '离职时间',
			sortable: true
		}, {
			field: 'empType',
			title: '类型'
		}, {
			field: 'empDomicileCity',
			title: '现居住城市'
		}, {
			field: 'empDomicileAddress',
			title: '户籍所在地'
		}, {
			field: 'empRole',
			title: '职务',
			formatter: function(value, row, index) {
				for (key in roles) {
					if (roles[key].roleId == value) {
						return roles[key].roleName;
					}
				}
			}
		}, {
			field: 'empDepartment',
			title: '部门',
			formatter: function(value, row, index) {
				for (key in departments) {
					if (departments[key].deptId == value) {
						return departments[key].deptName;
					}
				}
			}
		}] ,
		sortable: true,
        sortOrder: "asc",
        search: true,
   }
   
   var param = [{text:"姓名",name:"empName",type:"text",verify:"peopleName"},{text:"性别",name:"empSex",type:"select",option:[{key:"男",value:"男"},{key:"女",value:"女"},]},{text:"籍贯",name:"empNativePlace",type:"text",verify:"chineseStr"},{text:"学历",name:"empEducation",type:"select",verify:"",option:[{key:"初中",value:"初中"},{key:"高中/中专",value:"高中/中专"},{key:"大专",value:"大专"},{key:"本科",value:"本科"},{key:"硕士",value:"硕士"},{key:"博士",value:"博士"}]},{text:"入职日期",name:"dateScope",type:"text",verify:""},{text:"身份证",name:"empCard",type:"text",verify:"idCard"}];
   
   renderTable(cTable,data);
   
   createQueryPanel(param);

   $("input[class='form-control']").attr("placeholder","姓名|籍贯|性别|婚姻|学历");
   
   laydate.render({
     elem: '[name="empEntryDate"]'
     ,range: true
   });

   form.render();
})

$("#remove_btn").click(
	function(){
		requestRemoveData("empId","/human-resource/staff-files");
	}
)

$("#add_btn").click(function(){
	openOperateWindow({
		title: "新增员工档案",
		url: "/admin/enterpriseManagement/humanResources/staffFiles/staff-files-add.jsp"
	})
})

$("#modify_btn").click(function(){
	openOperateWindow({
		title: "修改员工档案",
		isUpdate: true,
		url: "/admin/enterpriseManagement/humanResources/staffFiles/staff-files-update.jsp"
	})
})
